package com.baturu.vin.benz.cleanData.dao;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: jiangxinlei
 * @Time: 2018/3/6 15:59
 **/
public interface BenzCleanDAO {

    @Update("CREATE TABLE ${tableName}_newdata like ${tableName}")
    int createTable(@Param("tableName") String tableName);

    @Insert({"insert into ${tableName}(${columnName})",
            "values ${columnValue}"})
    int insertCommon(@Param("tableName") String tableName,
                     @Param("columnName") String columnName,
                     @Param("columnValue") String columnValue);

    @Update("update benz_callout_position_newdata\n" +
            "    set callout = concat('00', callout)\n" +
            "    where LENGTH(callout)= 1")
    int updateCalloutPosition1();

    @Update("update benz_callout_position_newdata\n" +
            "    set callout = concat('0', callout)\n" +
            "    where LENGTH(callout)= 2")
    int updateCalloutPosition2();

    @Update("DROP  TABLE  IF EXISTS `benz_callout_position_add`")
    int dropBenzCalloutPosAdd();
    @Update("CREATE TABLE `benz_callout_position_add` (\n" +
            "            `id` int(11) NOT NULL AUTO_INCREMENT,\n" +
            "  `imgName` char(19) DEFAULT NULL COMMENT '图片名称',\n" +
            "            `callout` varchar(5) DEFAULT NULL COMMENT '图片位置',\n" +
            "            `topLeftX` int(11) DEFAULT '0',\n" +
            "            `topLeftY` int(11) DEFAULT '0',\n" +
            "            `bottomRightX` int(11) DEFAULT '0',\n" +
            "            `bottomRightY` int(11) DEFAULT '0',\n" +
            "    PRIMARY KEY (`id`),\n" +
            "    KEY `name_callout_IDX` (`imgName`,`callout`) USING BTREE\n" +
            ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='图片位置坐标表'")
    int createBenzCalloutPosAdd();
    @Insert("insert into benz_callout_position_add(`imgName`, `callout`, `topLeftX`, `topLeftY`, `bottomRightX`, `bottomRightY`)\n" +
            "    SELECT DISTINCT `imgName`, `callout`, `topLeftX`, `topLeftY`, `bottomRightX`, `bottomRightY` FROM `benz_callout_position_newdata`\n" +
            "    where (`imgName`, `callout`, `topLeftX`, `topLeftY`, `bottomRightX`, `bottomRightY`)\n" +
            "    not in (select DISTINCT `imgName`, `callout`, `topLeftX`, `topLeftY`, `bottomRightX`, `bottomRightY` from benz_callout_position)")
    int addCalloutPosAdd();
    @Update("drop table if EXISTS tmp_benz_missing_image")
    int dropMissingImage();
    @Update("create table tmp_benz_missing_image\n" +
            "    select DISTINCT imgName from benz_callout_position_newdata\n" +
            "    where imgName not in (select DISTINCT imgName from benz_callout_position)")
    int createMissingImage();


    @Update("create table benz_parts_mapping_ext_newdata like benz_parts_mapping_ext")
    int createPartsMappingExt();

    @Insert({"INSERT into benz_parts_mapping_ext_newdata(catNum, partsCode)",
            "SELECT DISTINCT catNum, cbPartsCode FROM bm_parts2_v"})
    int insertPartsMappingExt();

}
